home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / IP.H < prev    next >
C/C++ Source or Header  |  1996-12-23  |  8KB  |  252 lines

  1. /* Mods by PA0GRI (WFM IP access code ) */
  2. #ifndef    _IP_H
  3. #define    _IP_H
  4.  
  5. #ifndef    _GLOBAL_H
  6. #include "global.h"
  7. #endif
  8.  
  9. #ifndef    _MBUF_H
  10. #include "mbuf.h"
  11. #endif
  12.  
  13. #ifdef __GNUC__
  14. struct ip;            /* forward declaration for gcc */
  15. #endif
  16.  
  17. #ifndef    _IFACE_H
  18. #include "iface.h"
  19. #endif
  20.  
  21. #ifndef    _INTERNET_H
  22. #include "internet.h"
  23. #endif
  24.  
  25. #ifndef    _TIMER_H
  26. #include "timer.h"
  27. #endif
  28.  
  29. #define TLB        30    /* Default reassembly timeout, sec */
  30. #define    IPVERSION    4
  31. #define IP_CS_OLD    1    /* use saved checksum */
  32. #define IP_CS_NEW    0    /* calculate checksum */
  33.  
  34. extern char Hashtab[];    /* Modulus lookup table */
  35.  
  36. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  37. extern struct mib_entry Ip_mib[];
  38. #define    ipForwarding        Ip_mib[1].value.integer
  39. #define    ipDefaultTTL        Ip_mib[2].value.integer
  40. #define    ipInReceives        Ip_mib[3].value.integer
  41. #define    ipInHdrErrors        Ip_mib[4].value.integer
  42. #define    ipInAddrErrors        Ip_mib[5].value.integer
  43. #define    ipForwDatagrams        Ip_mib[6].value.integer
  44. #define    ipInUnknownProtos    Ip_mib[7].value.integer
  45. #define    ipInDiscards        Ip_mib[8].value.integer
  46. #define    ipInDelivers        Ip_mib[9].value.integer
  47. #define    ipOutRequests        Ip_mib[10].value.integer
  48. #define    ipOutDiscards        Ip_mib[11].value.integer
  49. #define    ipOutNoRoutes        Ip_mib[12].value.integer
  50. #define    ipReasmTimeout        Ip_mib[13].value.integer
  51. #define    ipReasmReqds        Ip_mib[14].value.integer
  52. #define    ipReasmOKs        Ip_mib[15].value.integer
  53. #define    ipReasmFails        Ip_mib[16].value.integer
  54. #define    ipFragOKs        Ip_mib[17].value.integer
  55. #define    ipFragFails        Ip_mib[18].value.integer
  56. #define    ipFragCreates        Ip_mib[19].value.integer
  57.  
  58. #define    NUMIPMIB    19
  59.  
  60. /* IP header, INTERNAL representation */
  61. #define IPLEN        20    /* Length of standard IP header */
  62. #define IP_MAXOPT    40    /* Largest option field, bytes */
  63. struct ip {
  64.     uint32 source;        /* Source address */
  65.     uint32 dest;        /* Destination address */
  66.     int16 length;        /* Total length */
  67.     int16 id;        /* Identification */
  68.     int16 offset;        /* Fragment offset in bytes */
  69.     int16 checksum;        /* Header checksum */
  70.  
  71.     struct {
  72.         char congest;    /* Congestion experienced bit (exp) */
  73.         char df;    /* Don't fragment flag */
  74.         char mf;    /* More Fragments flag */
  75.     } flags;
  76.  
  77.     char version;        /* IP version number */
  78.     char tos;        /* Type of service */
  79.     char ttl;        /* Time to live */
  80.     char protocol;        /* Protocol */
  81.     char optlen;        /* Length of options field, bytes */
  82.     char options[IP_MAXOPT];/* Options field */
  83. };
  84. #define    NULLIP    (struct ip *)0
  85.  
  86. /* Fields in option type byte */
  87. #define    OPT_COPIED    0x80    /* Copied-on-fragmentation flag */
  88. #define    OPT_CLASS    0x60    /* Option class */
  89. #define    OPT_NUMBER    0x1f    /* Option number */
  90.  
  91. /* IP option numbers */
  92. #define    IP_EOL        0    /* End of options list */
  93. #define    IP_NOOP        1    /* No Operation */
  94. #define    IP_SECURITY    2    /* Security parameters */
  95. #define    IP_LSROUTE    3    /* Loose Source Routing */
  96. #define    IP_TIMESTAMP    4    /* Internet Timestamp */
  97. #define    IP_RROUTE    7    /* Record Route */
  98. #define    IP_STREAMID    8    /* Stream ID */
  99. #define    IP_SSROUTE    9    /* Strict Source Routing */
  100.  
  101. /* Timestamp option flags */
  102. #define    TS_ONLY        0    /* Time stamps only */
  103. #define    TS_ADDRESS    1    /* Addresses + Time stamps */
  104. #define    TS_PRESPEC    3    /* Prespecified addresses only */
  105.  
  106. /* IP routing table entry */
  107. struct route {
  108.     struct route *prev;    /* Linked list pointers */
  109.     struct route *next;
  110.     uint32 target;        /* Target IP address */
  111.     unsigned int bits;    /* Number of significant bits in target */
  112.     uint32 gateway;        /* IP address of local gateway for this target */
  113.     int32 metric;        /* Hop count or whatever */
  114.     struct iface *iface;    /* Device interface structure */
  115.     int flags;
  116. #define    RTPRIVATE    0x1    /* Should the world be told of this route ? */
  117. #define    RTTRIG    0x2        /* Trigger is pending for this route */
  118.     struct timer timer;    /* Time until aging of this entry */
  119.     int32 uses;        /* Usage count */
  120. #ifdef RIP
  121.     int16 route_tag;    /* Tag used by RIP-2, N0POY 4/93 */
  122. #endif
  123. };
  124. #define    NULLROUTE    (struct route *)0
  125. extern struct route *Routes[32][HASHMOD];    /* Routing table */
  126. extern struct route R_default;            /* Default route entry */
  127.  
  128. /* IP access header entry  (WFM) */
  129. struct rtaccess{
  130.     struct rtaccess *nxtiface;    /* Linked list pointer */
  131.     struct rtaccess *nxtbits;
  132.     int16 status;        /* 0=permit, 1=deny */
  133.     int16 protocol;        /* 0=any, otherwise IP protocol # */
  134.     uint32 source;        /* Source IP address */
  135.     unsigned int sbits;    /* Number of significant bits in source */
  136.     uint32 target;        /* Target IP address */
  137.     unsigned int bits;    /* Number of significant bits in target */
  138.     struct iface *iface;    /* Device interface structure */
  139.     int16 lowport;        /* tcp & udp port range. low=0 implies all */
  140.     int16 highport;
  141. };
  142. #define NULLACCESS    (struct rtaccess *)0
  143. extern struct rtaccess *IPaccess;
  144. /* end WFM access control */
  145.  
  146. /* Cache for the last-used routing entry, speeds up the common case where
  147.  * we handle a burst of packets to the same destination
  148.  */
  149. struct rt_cache {
  150.     uint32 target;
  151.     struct route *route;
  152. };
  153.  
  154.  
  155. /* Reassembly descriptor */
  156. struct reasm {
  157.     struct reasm *next;    /* Linked list pointer */
  158.     struct timer timer;    /* Reassembly timeout timer */
  159.     struct frag *fraglist;    /* Head of data fragment chain */
  160.     int16 length;        /* Entire datagram length, if known */
  161.     uint32 source;        /* src/dest/id/protocol uniquely describe a datagram */
  162.     uint32 dest;
  163.     int16 id;
  164.     char protocol;
  165. };
  166. #define    NULLREASM    (struct reasm *)0
  167.  
  168. /* Fragment descriptor in a reassembly list */
  169. struct frag {
  170.     struct frag *prev;    /* Previous fragment on list */
  171.     struct frag *next;    /* Next fragment */
  172.     struct mbuf *buf;    /* Actual fragment data */
  173.     int16 offset;        /* Starting offset of fragment */
  174.     int16 last;        /* Ending offset of fragment */
  175. };
  176. #define    NULLFRAG    (struct frag *)0
  177.  
  178. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  179.  
  180. /* Structure for handling raw IP user sockets */
  181. struct raw_ip {
  182.     struct raw_ip *next;    /* Linked list pointer */
  183.  
  184.     struct mbuf *rcvq;    /* receive queue */
  185.     void (*r_upcall) (struct raw_ip *);
  186.     int protocol;        /* Protocol */
  187.     int user;        /* User linkage */
  188. };
  189. #define    NULLRIP    ((struct raw_ip *)0)
  190.  
  191. /* Transport protocol link table */
  192. struct iplink {
  193.     char proto;
  194.     void (*funct) (struct iface *,struct ip *,struct mbuf *,int);
  195. };
  196. extern struct iplink Iplink[];
  197.  
  198. /* IP heard structure */
  199. struct iph {
  200.     struct iph *next;
  201.     uint32 addr;
  202.     struct iface *iface;
  203.     long count;
  204.     long time;
  205. };
  206. #define NULLIPH (struct iph *)0
  207. #define MAXIPHEARD 16
  208.  
  209. /* In ip.c: */
  210. #ifdef MSDOS
  211. void ip_garbage (int drastic);
  212. #endif
  213. void ip_recv (struct iface *iface,struct ip *ip,struct mbuf *bp,
  214.     int rxbroadcast);
  215. void ipip_recv (struct iface *iface,struct ip *ip,struct mbuf *bp,
  216.     int rxbroadcast);
  217. int ip_send (uint32 source,uint32 dest,char protocol,char tos,char ttl,
  218.     struct mbuf *bp,int16 length,int16 id,char df);
  219. struct raw_ip *raw_ip (int protocol,void (*r_upcall) (struct raw_ip *));
  220. void del_ip (struct raw_ip *rrp);
  221.  
  222. /* In iproute.c: */
  223. void ipinit (void);
  224. int16 ip_mtu (uint32 addr);
  225. int ip_encap (struct mbuf *bp,struct iface *iface,uint32 gateway,
  226.     int prec,int del,int tput,int rel);
  227. int ip_route (struct iface *i_iface,struct mbuf *bp,int rxbroadcast);
  228. uint32 locaddr (uint32 addr);
  229. void rt_merge (int trace);
  230. struct route *rt_add (uint32 target,unsigned int bits,uint32 gateway,
  231.     struct iface *iface,int32 metric,int32 ttl,char private);
  232. int rt_drop (uint32 target,unsigned int bits);
  233. struct route *rt_lookup (uint32 target);
  234. struct route *rt_blookup (uint32 target,unsigned int bits);
  235. void addaccess (int16 protocol,uint32 source,unsigned int sbits,
  236.     uint32 target,unsigned int tbits,struct iface *ifp,
  237.     int16 low,int16 high,int16 permit);
  238.  
  239. /* In iphdr.c: */
  240. int16 cksum (struct pseudo_header *ph,struct mbuf *m,int16 len);
  241. int16 eac (int32 sum);
  242. struct mbuf *htonip (struct ip *ip,struct mbuf *data,int cflag);
  243. int ntohip (struct ip *ip,struct mbuf **bpp);
  244.  
  245. /* In either lcsum.c or pcgen.asm: */
  246. int16 lcsum (int16 *wp,int16 len);
  247.  
  248. /* In ipcmd.c */
  249. void log_ipheard (uint32 addr, struct iface *iface);
  250.  
  251. #endif /* _IP_H */
  252.